package com.weimob.mcloud.wechatwork.customer.third.pmc;

import com.alibaba.dubbo.config.annotation.Reference;
import com.weimob.mcloud.wechatwork.core.adapter.pojo.dto.pmc.request.PmcRequest;
import com.weimob.mcloud.wechatwork.core.adapter.pojo.dto.pmc.response.PmcResponse;
import com.weimob.mcloud.wechatwork.core.adapter.service.pmc.PmcParamsService;
import com.weimob.mcloud.wechatwork.customer.service.user.enums.PmcOperationSourceEnum;
import com.weimob.mcloud.wechatwork.customer.service.user.enums.PmcParamKindEnum;
import com.weimob.saas.mcloud.wechatwork.integration.common.request.BasicInfo;
import com.weimob.soa.common.utils.SoaUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * PMC对接客户端
 *
 * @Author LeoLee
 * @Date 2022/6/22 10:52
 * @Version 1.0
 */
@Component
@Slf4j
public class PmcProxy {

    @Reference
    private PmcParamsService pmcParamsService;

    public PmcResponse getPmcParamValues(BasicInfo basicInfo, PmcOperationSourceEnum operationSourceEnum, Long wid, String url, Long vid) {
        PmcRequest pmcRequest = new PmcRequest();
        pmcRequest.setBosId(basicInfo.getBosId());
        pmcRequest.setProductId(basicInfo.getProductId());
        pmcRequest.setProductInstanceId(basicInfo.getProductInstanceId());
        //这里由于分享链接进店规则的影响，不能直接使用basicINfo的vid，因为有些分享链接自带vid
        pmcRequest.setVid(vid);
        pmcRequest.setVidType(basicInfo.getVidType());
        pmcRequest.setProductVersionId(basicInfo.getProductVersionId());
        pmcRequest.setMerchantId(basicInfo.getMerchantId());
        pmcRequest.setOperationSource(operationSourceEnum.getCode());
        pmcRequest.setWid(wid);
        pmcRequest.setUrl(url);
        //后端dubbo对接：有局限性，仅能加到的参数类型有：1-关系链参，3-分享动态参,当前业务场景就传3就好了
        pmcRequest.setKinds(Arrays.asList(PmcParamKindEnum.share_dynamic_param.getCode()));
        return SoaUtil.unpack(pmcParamsService.getPmcParamValues(pmcRequest));
    }

}
